﻿using System;
using System.Collections.Generic;
using MS.CodePlex.PermutationTools;

namespace Sample
{
    class Program
    {



        static void Main(string[] args)
        {
            CombinationGeneratorSample();
            PermutationCollectionSample();
        }

        private static void PermutationCollectionSample()
        {
            PermutationCollection pg = new PermutationCollection();
            string[] stringParameters = { "default", "abcdef", "1234567890", "" };
            int[] intParameters = { 1, 3, 5 };

            pg.Add("PrimeNumber", intParameters);
            pg.Add("UserName", stringParameters);

            //automatically add all the members of an enum.
            pg.Add("GenericUriParserOption", typeof(System.GenericUriParserOptions));

            //Remove one of the enum members from an added enum.
            pg.RemoveListMember("GenericUriParserOption", System.GenericUriParserOptions.NoUserInfo);

            Console.WriteLine(pg.NumOfPermutations);

            //display every combination of paramters
            foreach (Dictionary<string, object> parameters in pg)
            {
                int prime = (int)parameters["PrimeNumber"];
                string username = (string)parameters["UserName"];
                System.GenericUriParserOptions option = (GenericUriParserOptions)parameters["GenericUriParserOption"];
                Console.WriteLine("Prime='{0}' UserName='{1}' Option='{2}'", prime, username, option);
            }
        }

        /* output:
        132
        Prime='1' UserName='default' Option='Default'
        Prime='3' UserName='default' Option='Default'
        Prime='5' UserName='default' Option='Default'
        Prime='1' UserName='abcdef' Option='Default'
        Prime='3' UserName='abcdef' Option='Default'
        Prime='5' UserName='abcdef' Option='Default'
        Prime='1' UserName='1234567890' Option='Default'
        Prime='3' UserName='1234567890' Option='Default'
        Prime='5' UserName='1234567890' Option='Default'
        Prime='1' UserName='' Option='Default'
        Prime='3' UserName='' Option='Default'
        Prime='5' UserName='' Option='Default'
        Prime='1' UserName='default' Option='GenericAuthority'
        Prime='3' UserName='default' Option='GenericAuthority'
        Prime='5' UserName='default' Option='GenericAuthority'
        Prime='1' UserName='abcdef' Option='GenericAuthority'
        Prime='3' UserName='abcdef' Option='GenericAuthority'
        Prime='5' UserName='abcdef' Option='GenericAuthority'
        Prime='1' UserName='1234567890' Option='GenericAuthority'
        Prime='3' UserName='1234567890' Option='GenericAuthority'
        Prime='5' UserName='1234567890' Option='GenericAuthority'
        Prime='1' UserName='' Option='GenericAuthority'
        Prime='3' UserName='' Option='GenericAuthority'
        Prime='5' UserName='' Option='GenericAuthority'
        ...
        */


        enum stuff
        {
            A,
            B,
            C,
            D,
            E
        }


        private static void CombinationGeneratorSample()
        {
            //get a list of everyone combinations of 3 items from the list.      
            CombinationGenerator<stuff> cg = new CombinationGenerator<stuff>(typeof(stuff), 3);
            Console.WriteLine(cg.NumOfCombinations);
            foreach (stuff[] oa in cg)
            {
                foreach (stuff o in oa)
                {
                    Console.Write("{0} ", o);
                }
                Console.WriteLine();
            }


            Console.WriteLine("----------------------------------");
            Console.WriteLine(cg.NumOfOneToNCombinations);
            //Get a list of all the combinations of 1, 2..N items from the list where N is the number of items in the list.
            foreach (stuff[] oa in cg.OneToNPermutations)
            {
                foreach (stuff o in oa)
                {
                    Console.Write("{0} ", o);
                }
                Console.WriteLine();
            }
        }
        /* Output:
        10
        A B C
        A B D
        A B E
        A C D
        A C E
        A D E
        B C D
        B C E
        B D E
        C D E
        --------------------------------
        31
        A
        B
        C
        D
        E
        E
        A B
        A C
        A D
        A E
        B C
        B D
        B E
        C D
        C E
        D E
        D E
        A B C
        A B D
        A B E
        A C D
        A C E
        A D E
        B C D
        B C E
        B D E
        C D E
        C D E
        A B C D
        A B C E
        A B D E
        A C D E
        B C D E
        B C D E
        A B C D E
        */



    }
}
